

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

#include "common/utils.hpp"

int countNodes(TreeNode* root) {
    int ret = 0;
    std::queue<TreeNode*> queue;

    if (root != nullptr) queue.push(root);

    while(!queue.empty()) {
        int size = queue.size();
        for (int i = 0; i < size; i++) {
            TreeNode* node = queue.front();
            queue.pop();

            if (node->left != nullptr) queue.push(node->left);
            if (node->right != nullptr) queue.push(node->right);
        }

        ret += size;
    }

    return ret;
}

extern TreeNode* commonRoot;

int main() {
    int res = countNodes(commonRoot);
    std::cout << "res: " << res << "\n";
}